package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.Emp;
import com.itheima.entity.EmpQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
//    @Override
//    public PageBean page(Integer page, Integer pageSize) {
////        Long total = empMapper.count();
////        Integer start = (page - 1) * pageSize;
////        List<Emp> rows = empMapper.page(start, pageSize);
////        return new PageBean(total, rows);
//
//        //1. 设置分页参数
//        PageHelper.startPage(page, pageSize);
//
//        List<Emp> empList = empMapper.list();
//        Page<Emp> empPage = (Page<Emp>) empList;
//        return new PageBean(empPage.getTotal(), empPage.getResult());
//    }

    @Override
    public PageBean page(EmpQueryParam empQueryParam) {
        PageHelper.startPage(empQueryParam.getPage(), empQueryParam.getPageSize());
        List<Emp> empList = empMapper.list(empQueryParam);
        Page<Emp> empPage = (Page<Emp>) empList;
        return new PageBean(empPage.getTotal(), empPage.getResult());
    }
}
